//
//  FbeeInputView.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/6.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "FbeeInputView.h"

@implementation FbeeInputView

@synthesize textF;

-(instancetype)initWithText:(NSString *)placeHolder
{
    self = [super initWithFrame:CGRectMake(0, 0, 280*UISCALE, 50*UISCALE)];
    
    if (self) {
        
        UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        bg.backgroundColor = UIColorFromRGB(0xECECEC);
        bg.layer.cornerRadius = self.height/2;
        [self addSubview:bg];
        
        textF = [[UITextField alloc] initWithFrame:CGRectMake(18*UISCALE, 0, self.width - 18*UISCALE*2, self.height)];
        textF.autocorrectionType = UITextAutocorrectionTypeNo;
        textF.clearButtonMode = UITextFieldViewModeAlways;
        textF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        
        NSMutableAttributedString * mAttribute = [[NSMutableAttributedString alloc] initWithString:placeHolder];
        [mAttribute addAttribute:NSFontAttributeName
                           value:[UIFont systemFontOfSize:16.0f]
                           range:NSMakeRange(0, placeHolder.length)];
        
        [mAttribute addAttribute:NSForegroundColorAttributeName
                           value:FBEE_COLOR_INFO
                           range:NSMakeRange(0, placeHolder.length)];
        
        textF.attributedPlaceholder = mAttribute;
        
        [self addSubview:textF];
        
    }
    
    return self;
}

-(void)setKeyboardType:(UIKeyboardType)keyboardType
{
    [textF setKeyboardType:keyboardType];
}

-(void)becomeFirstResponder
{
    [textF becomeFirstResponder];
}

-(void)resignFirstResponder
{
    [textF resignFirstResponder];
}

-(NSString *)getText
{
    if (textF.text.length > 0) {
        return textF.text;
    }
    return @"";
}

@end
